<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Login</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <link rel="icon" href="{{ url_for('static', filename='logo.png') }}" type="image/png">
    <style>
        body {
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background-image: url('/static/images/Background_image.jpeg');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
        }
        .login-container {
            width: 350px;
            padding: 30px;
            background: rgba(252, 252, 252, 0.95);
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0, 0, 0, 0.1);
        }
        h1 {
            font-size: 24px;
            margin-bottom: 25px;
            text-align: center;
            color: #333;
        }
        .form-group {
            margin-bottom: 20px;
            display: flex;
            align-items: center;
        }
        .form-group label {
            width: 70px;
            margin-right: 10px;
            font-size: 14px;
            color: #555;
        }
        .form-control {
            flex: 1;
            padding: 10px 15px;
            font-size: 14px;
            border: 1px solid #ddd;
            border-radius: 4px;
            height: 40px;
        }
        .btn {
            width: 100%;
            padding: 10px;
            font-size: 16px;
            font-weight: 500;
            background-color: #4285f4;
            border: none;
            border-radius: 4px;
            margin-top: 10px;
        }
        .btn:hover {
            background-color: #3367d6;
        }
        .alert {
            margin-top: 15px;
        }
        .register-link {
            text-align: center;
            margin-top: 20px;
            font-size: 14px;
            color: #666;
        }
        .register-link a {
            color: #4285f4;
            text-decoration: none;
        }
    </style>
</head>
<body>
    <div class="login-container">
        <h1>登录</h1>

        <!-- Error message display -->
        {% with messages = get_flashed_messages(with_categories=true) %}
            {% if messages %}
                {% for category, message in messages %}
                    {% if category == 'error' %}
                        <div class="alert alert-danger">
                            {{ message }}
                        </div>
                    {% endif %}
                {% endfor %}
            {% endif %}
        {% endwith %}

        <form action="{{ url_for('login') }}" method="post">
            <div class="form-group">
                <label for="username">用户名：</label>
                <input type="text" class="form-control" id="username" name="username" placeholder="请输入用户名" value="{{ request.form.username if request.form }}" required>
            </div>
            <div class="form-group">
                <label for="password">密码：</label>
                <input type="password" class="form-control" id="password" name="password" placeholder="请输入密码" required>
            </div>
            <button type="submit" class="btn btn-primary">登 录</button>
        </form>
        <div class="register-link">
            还没有账号？<a href="{{ url_for('register') }}">立即注册</a>
        </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            document.getElementById('password').value = '';
        });
    </script>
</body>
</html>